<template>
  <div class="login">
    <!--1.视图-->
    <el-form :model="formInline" class="login-form">
      <el-form-item label="账号">
        <el-input v-model="formInline.userName" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input show-password v-model="formInline.password" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item label="验证码">
        <el-input v-model="formInline.code" placeholder="验证码"></el-input>
        <img :src="codeUrl" @click="getCode">
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login">登录</el-button>
        <el-button type="primary" @click="oauth">Oauth登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "LoginView",
  data() {
    return {
      //2.属性定义
      formInline:{},
      codeUrl:'',
    }
  }, methods: {
    //3.方法
    oauth(){
      let client_id = "93d84f17-3b2a-4b3f-a856-89c734971a0b";
      let redirect_uri = "http://localhost:8080/login";
      window.location.href="http://localhost:9401/oauth/authorize?response_type=code&client_id="+client_id+"&redirect_uri="+redirect_uri+"&scope=all&state=normal";
    },
    login(){
      this.axios.post("http://localhost:8000/carsystem/sysUser/login",this.formInline).then(res=>{
        if(res.data.code==200){
          this.$message.success(res.data.msg);
          sessionStorage.setItem("token",res.data.data.token);
          this.$router.push("/")
        }else{
          this.$message.error(res.data.msg);
        }
      })
    },
    getCode(){
      let t = new Date().getTime();
      let uid = localStorage.getItem("uid");
      this.formInline.uid=uid;
      this.codeUrl="http://localhost:8000/carsystem/sysUser/getCode?t="+t+'&uid='+uid;
    }
  }, created() {
    //4.钩子函数
    this.getCode();
  }
}
</script>

<style>
.login {
  width: 1920px;
  height: 1080px;
  background-image: url('https://www.toopic.cn/public/uploads/small/1718867255117171886725522.jpg');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.login-form {
  border-radius: 6px;
  width: 400px;
  padding: 25px 25px 5px 25px;
}
</style>